// pages/index/chooseLocation/chooseLocation.js

const app = getApp();

Page({

	/**
	 * 页面的初始数据
	 */
	data: {

	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {

	},


	getlacation(){
		wx.chooseLocation({
			success: function (res) {
				console.log(res);
			}, fail: function () {

			}, complete: function () {
			}
		})
	},

	checkPermission(name, title,that) {
		return this.wxPromise("getSetting")
			.then((res) => {
				console.log(res);
				if (res.authSetting[name]) {
					return this.resolve(true);
				}
				if (res.authSetting[name] === false) {
					return this.reject();
				}
				return this.resolve(false);
			}).catch(() => {
				// wx.navigateTo({
				//     // url: "/pages/common/auth/auth?scope=" + name + "&title=" + title
				// });
				that.tips();
				return this.resolve(false);
			});
	},

	checkAuth: function () {
		let that = this;
		app.func.wxPromise("authorize", {scope: "scope.userLocation"})
			.then(() => {
				return app.func.wxPromise("chooseLocation");
			}, () => {
				return app.func.checkPermission("scope.userLocation", "地理位置", that);
			})
			.then((res) => {
				console.log(res);
			})
			.catch((error) => {
				console.log(error);
			});
	},

	cancel: function () {
		this.setData({tips: false});
	},
	tips: function () {
		this.setData({tips: true});
	},

	setting: function () {
		this.setData({tips: false});
		app.func.wxPromise("openSetting")
			.then((res) => {
				if (res.authSetting[this.data.scope]) {
					wx.navigateBack({
						delta: 1
					});
				}
			})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})
